


//
//  CPJWelcomeView.swift
//  Sina
//
//  Created by YYY on 2017/8/11.
//  Copyright © 2017年 成品家（北京）网路科技有限公司. All rights reserved.
//

import UIKit

import SDWebImage

class CPJWelcomeView: UIView {

    @IBOutlet weak var iconImageView: UIImageView!
    
    @IBOutlet weak var nickInfo: UILabel!
    
    
    @IBOutlet weak var bottomConstraint: NSLayoutConstraint!
    
    class func welcomeView() -> CPJWelcomeView
    {
        let nib = UINib(nibName: "CPJWelcomeView", bundle: nil)
        let view = nib.instantiate(withOwner: nil, options: nil)[0] as! CPJWelcomeView
        view.frame = UIScreen.main.bounds
        return view
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        
    }
    
    override func awakeFromNib() {

        guard let urlString = CPJNetworkManager.shared.userAccount.avatar_large,
        let url = URL(string: urlString)else
        {
            return
        }
        //self.iconImageView.sd_setImage(with: url)
        iconImageView.sd_setImage(with: url, placeholderImage: UIImage(named: "avatar_default_big"))
        //设置图片圆角
//        self.iconImageView.layer.masksToBounds = true
//        self.iconImageView.layer.cornerRadius = self.iconImageView.width * 0.5
    }
    //视图被添加到window上，表示视图已经显示
    override func didMoveToWindow() {
        super.didMoveToWindow()
        self.layoutIfNeeded()
        bottomConstraint.constant = bounds.size.height - 200
        
        UIView.animate(withDuration: 3.0, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: [], animations: {
            
            self.layoutIfNeeded()
            
        }) { (_) in
            
            UIView.animate(withDuration: 1, animations: { 
                self.nickInfo.alpha = 1
            }, completion: { (_) in
                self.removeFromSuperview()
            })
           
        }
    }
    
    //自动布局系统更新完成约束后，会自动调用此方法
    //通常是对子视图布局进行修改
//    override func layoutSubviews() {
//        
//    }
}
